package mobile.couponow;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;

import com.phonegap.DroidGap;


public class App extends DroidGap {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setIntegerProperty("splashscreen", R.drawable.splash);
		super.loadUrl("http://coupon-now.appspot.com?username=" + RegistrationUtils.getUserMailAdress(this), 2000);
		//was as separate function. maybe should be called within onResume()
		C2DMessaging.register(this, "couponnowmobile@gmail.com");
	}

	protected void onResume() {
		super.onResume();
		super.loadUrl("http://coupon-now.appspot.com?username=" + RegistrationUtils.getUserMailAdress(this), 2000);
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event){
		if (keyCode == KeyEvent.KEYCODE_BACK){
			AlertDialog.Builder builder = new AlertDialog.Builder(App.this);
			
			builder.setMessage("Are You Sure You Want to Quit?").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener()
			{

				@Override
				public void onClick(DialogInterface dialog, int which)
				{						
					finish();

				}
			}).setNegativeButton("CANCEL", new DialogInterface.OnClickListener()
			{
				public void onClick(DialogInterface dialog, int id)
				{
					dialog.cancel();
				}
			}).show();
			
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

}
